package com.focus.xyz.union.pages.frontend.tables;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BaseTable;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Created by chenmeng on 2016/4/19.
 */
public class WebSiteTable extends BaseTable {
    @FindBy(xpath = "//table[@class='tab-info tab-border']/tbody")
    private WebElement table;
    private static final String LINK_XPATH = "td[8]/a";
    private static final String STATUS_XPATH = "td[7]/div";

    public WebSiteTable(WebDriver driver, Action action){
        super(action);
        PageFactory.initElements(driver,this);
        super.table = table;
    }

    @Override
    protected By getLinkLocator() throws Exception {
        return By.xpath("td[8]/a");
    }

    @Override
    protected By getLocator(int index) throws Exception {
        return By.xpath("td[" + index + "]/div");
    }

    public void linkModify(String key) throws Exception{
        selectRowAndClickLink(table,key,"修改");
    }

    /*
    * 删除网站
    * */
    public void linkDel(String key) throws Exception{
        selectRowAndClickLink(table,key,"删除");
        action.waitForAlert();
        action.acceptAlert();
    }

    public void linkDetail(String key) throws Exception{
        selectRowAndClickLink(table,key,"查看频道");
    }

    //获取频道状态
    public String getStatus(String key) throws Exception{
        return getCellText(table,key,7);
    }

}
